import json


def readJson(filePath):
    with open(filePath, 'r', encoding='utf8') as fp:
        json_data = json.load(fp)
    return json_data


def readHear(filePath):
    header = {}
    with open(filePath, 'r', encoding='utf8') as hd:
        headers = hd.readlines()
        for i in headers:
            if len(i) >= 4:
                key = i.split(" ")[0].strip(":")
                value = ""
                for j in range(len(i.split(" "))):
                    if j != 0:
                        value += i.split(" ")[j].replace("\n", "").replace(" ", "").strip("\n")
                header.update({key: value.strip("\n")})
    return header


def readPsdFile(path):
    sect = 3
    fs = open(path, 'r', encoding='utf-8')
    context = []
    for i in fs.readlines():
        sstr = ""
        for j in i:
            sstr += chr(ord(j) - sect)
        context.append(sstr)
    return context


def writePsdFile(path, context):
    sect = 3
    fs = open(path,'a+',encoding='utf-8')
    sstr = ""
    for i in context:
        sstr += chr(ord(i) + sect)
    fs.writelines("\n" + sstr + "\n")
    fs.close()

def overWritePsdFile(path, contexts):
    sect = 3
    fs = open(path, 'w+', encoding='utf-8')

    for context in contexts:
        sstr = ""
        for i in context:
            sstr += chr(ord(i) + sect)
        fs.writelines( "\n" +sstr+"\n")
    fs.close()



# writePsdFile(path="../log/account.txt",context='你说的12313213')
# context = readPsdFile(path="../log/account.txt")
# print(context)